package com.wxy.ej.flow.modules.act.controller;

import com.rt.easyjava.common.base.PageDto;
import com.rt.easyjava.common.base.Result;
import com.wxy.ej.flow.modules.act.dto.ProcessDefinitionDto;
import com.wxy.ej.flow.modules.act.dto.TaskDto;
import com.wxy.ej.flow.modules.act.dto.TaskQueryDto;
import com.wxy.ej.flow.modules.act.service.ActivitiService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 动态表单
 * https://blog.csdn.net/sdufexsh/article/details/83111965
 */

@Slf4j
@Api(tags = "Activiti 内置表单 控制类")
@RequestMapping("/act")
@RestController
public class ActivitiController  {

    @Resource
    ActivitiService activitiService;


    @ApiOperation("获取启动流程上定义的动态表单")
    @GetMapping(value = "/queryStartFormKey")
    public Result queryStartFormKey(String procDefKey) {
        return activitiService.queryStartFormKey(procDefKey);
    }

    @ApiOperation("获取启动流程上定义的动态表单")
    @GetMapping(value = "/queryFormKeyList")
    public Result queryFormKeyList(String taskId, int isHisTask) {
        return activitiService.queryFormKeyList(taskId, isHisTask);
    }
    @ApiOperation("获取启动流程上定义的动态表单")
    @GetMapping(value = "/queryFormKeyListByProcInstId")
    public Result queryFormKeyListByProcInstId(String procInstId) {
        return activitiService.queryFormKeyListByProcInstId(procInstId);
    }

    @ApiOperation("启动流程ByKey")
    @PostMapping(value = "/startProcByProcDefKey")
    public Result startProcByProcDefKey(@RequestBody ProcessDefinitionDto processDefinitionDto){
        return activitiService.startProcByProcDefKey(processDefinitionDto);
    }

    @ApiOperation("完成任务")
    @PostMapping(value = "/completeByTaskId")
    public Result completeByTaskId(@RequestBody TaskDto taskDto){
        return activitiService.completeByTaskId(taskDto);
    }

    @ApiOperation("我发起的流程")
    @PostMapping(value = "/listMyStartProcInst")
    public Result listMyStartProcInst(@RequestBody TaskQueryDto taskQueryDto) {
        return activitiService.listStartProcInstByUserId(taskQueryDto);
    }


    @ApiOperation("我的待办任务")
    @PostMapping(value = "/listMyWaitingTask")
    public Result listMyWaitingTask(@RequestBody PageDto pageDto) {
        return activitiService.listWaitingTaskByLoginUserId(pageDto);
    }

    @ApiOperation("我完成的任务")
    @PostMapping(value = "/listMyCompleteTask")
    public Result listMyCompleteTask(@RequestBody PageDto pageDto) {
        return activitiService.listMyCompleteTaskByLoginUserId(pageDto);
    }

    @ApiOperation("根据流程实例Id,获取实时流程图片")
    @GetMapping(value = "/getFlowImgByProcInstId")
    public Result getFlowImgByProcInstId(String procInstId) {
        return activitiService.getFlowImgByProcInstId(procInstId);
    }

    @ApiOperation("分配任务 By ProcInstId")
    @PostMapping(value = "/assignTaskToUserByProcInstId")
    public Result assignTaskToUserByProcInstId(String processInstanceId, String userId){
        return activitiService.assignTaskToUserByProcInstId(processInstanceId, userId);
    }

    @ApiOperation("分配任务 By TaskId")
    @PostMapping(value = "/assignTaskToUserByTaskId")
    public Result assignTaskToUserByTaskId(String taskId, String userId){
        return activitiService.assignTaskToUserByTaskId(taskId, userId);
    }


}
